<template>
  <div>
    <header class="header">
      <h1>任务列表</h1>
      <input
        class="new-todo"
        placeholder="请输入要做的事情"
        autofocus
        @keyup.enter="add()"
        v-model="todoname"
      />
    </header>
  </div>
</template>

<script>
export default {
  data() {
    return {
      todoname: "",
    };
  },
  methods: {
    add() {
      // 子传父，将任务名称传递给父组件
      this.$emit("add", this.todoname);
      // 清空输入框
      this.todoname = "";
    },
  },
};
</script>

<style lang="scss" scoped>
</style>